import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {getAllRoleList} from "@/api/demo/system";
import {defHttp} from "@/utils/http/axios";

export const columns: BasicColumn[] = [
  {
    title: '设备TOPIC',
    dataIndex: 'topic',
  },
  {
    title: '匹配逻辑',
    dataIndex: 'type',
    customRender: ({ text }) => {
      return render.renderDict(text, 'trigger_match_logic');
    },
  },
  {
    title: '匹配值',
    dataIndex: 'msgValue',
  },
  {
    title: '触发器',
    dataIndex: 'triggerId_dictText',
  },
  {
    title: '描述',
    dataIndex: 'description',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '设备TOPIC',
    field: 'topic',
    component: 'Input',
  },
  {
    label: '匹配逻辑',
    field: 'type',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'trigger_match_logic',
      placeholder: '请选择状态',
      stringToNumber: true,
    },
  },
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '设备TOPIC',
    field: 'topic',
    component: 'Input',
    required: true,
  },
  {
    label: '匹配逻辑',
    field: 'type_dictText',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'trigger_match_logic',
      placeholder: '请选择',
      stringToNumber: true,
    },
    required: true,
  },
  {
    label: '匹配值',
    field: 'msgValue',
    component: 'Input',
  },
  {
    label: '触发器',
    field: 'triggerId',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/coze/iotUserTrigger/list' }),
      labelField: 'triggerName',
      valueField: 'id',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
    },
    required: true,
  },
  {
    label: '描述',
    field: 'description',
    component: 'Input',
  },
];
